package com.zxy.barometer.controller;

import com.zxy.barometer.common.config.MessageResultConstant;
import com.zxy.barometer.message.response.BaseResult;
import lombok.extern.slf4j.Slf4j;

/**
 * 控制器基类
 *
 * @author zxy
 */
@Slf4j
class BaseController {
    public BaseResult getErrorMessage(Exception e){
        BaseResult baseResult;
        if (e.getCause() instanceof org.apache.ibatis.exceptions.TooManyResultsException) {
            log.error("查询到多个相同数据信息");
            baseResult = new BaseResult(MessageResultConstant.DATA_ERROR, "查询到多个相同数据信息，请用唯一编码");
        } else {
            log.error("其他查询错误", e);
            baseResult = new BaseResult(MessageResultConstant.DATA_ERROR, "其他查询错误");
        }
        return baseResult;
    }
}
